$(function () {
    $("#jqGrid").jqGrid({
        url: '../scheduleLog/list',
        datatype: "json",
        postData: {
            status: 2,
            cond: {"startTime_greaterEqual": dateFtt("yyyy-MM-dd hh:mm:ss", new Date(new Date().setHours(0, 0, 0, 0)))}
        },
        colModel: [
            {label: 'id', name: 'id', width: 50, key: true},
            {label: '实例Id', name: 'instanceId', index: 'instance_id', width: 80},
            {label: '实例明细Id', name: 'instanceDtlId', index: 'instance_dtl_id', width: 80},
            {label: '作业Id', name: 'workItemId', index: 'work_item_id', width: 80},
            {label: '作业名称', name: 'workItemName', index: 'work_item_name', width: 80},
            {label: '作业明细id', name: 'workItemDtlId', index: 'work_item_dtl_id', width: 80},
            {label: '作业明细名称', name: 'workItemDtlName', index: 'work_item_dtl_name', width: 80},
            {
                label: '状态', name: 'status', width: 50, formatter: function (value, options, row) {
                    var show = '';
                    if (value === 1) {
                        show = '<span class="label label-info">进行中</span>';
                    } else if (value === 3) {
                        show = '<span class="label label-success">成功</span>';
                    } else {
                        show = '<span class="label label-danger pointer" onclick="vm.showError(' + row.id + ')">失败</span>';
                    }
                    return show;
                }
            },
            {label: 'error', name: 'error', width: 80, hidden: true},
            {label: '开始时间', name: 'startTime', index: 'start_time', width: 80},
            {label: '结束时间', name: 'endTime', index: 'end_time', width: 80}
        ],
        viewrecords: true,
        height: 370,
        rowNum: 10,
        rowList: [10, 20, 30],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.data",
            page: "page.pageNo",
            total: "page.pageCount",
            records: "page.count"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        isShowCond: false,
        btnText: '查询',
        qryForm: {},
        mainInfo: {}
    },
    created: function () {
        this.getInfo()
    },
    methods: {
        getInfo: function () {
            $.get("../sys/main/info/", function (r) {
                vm.mainInfo = r.mainInfo;
            });
        },
        reset: function () {
            this.qryForm.paramKey = '';
        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {},
                page: 1
            }).trigger("reloadGrid");
        },
        toggle: function () {
            this.isShowCond = !this.isShowCond;

            if (this.isShowCond == true) {
                this.btnText = "隐藏"
            } else if (this.isShowCond == false) {
                this.btnText = "查询"
            }

        },
        create: function (event) {
            location.href = "user_add.html";
        },
        update: function (event) {
            var userId = getSelectedRow();
            if (userId == null) {
                return;
            }

            location.href = "user_add.html?userId=" + userId;
        },
        del: function (event) {
            var userIds = getSelectedRows();
            if (userIds == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: "../sys/user/delete",
                    data: JSON.stringify(userIds),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        }
    }
});


// setInterval(function(){
//     $("#jqGrid").trigger("reloadGrid");
//     vm.getInfo();
// },10*1000);